package group.hhsw.purchase.service.impl;

import group.hhsw.common.model.vo.DetailOrder;
import group.hhsw.common.model.params.Check;
import group.hhsw.feign.clients.ProductClient;
import group.hhsw.purchase.service.PurchaseService;
import group.hhsw.purchase.utils.CalculateDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service("6")
public class CalculateDateService implements PurchaseService {

    @Autowired
    private ProductClient productClient;

    @Override
    public DetailOrder atomicService(Check check) {
        Integer term = productClient.getTerm(check.getProductId());
        DetailOrder detailOrder = new DetailOrder();
        detailOrder.setStartDate(LocalDate.now());
        LocalDate endDate = CalculateDate.calculate(term, LocalDate.now());
        detailOrder.setEndDate(endDate);
        return detailOrder;
    }

}
